//
//  LOLVideoXTableViewCell.m
//  LOLXXbox
//
//  Created by mac on 16/3/1.
//  Copyright © 2016年 Grasstrio. All rights reserved.
//

#import "LOLVideoXTableViewCell.h"
#define CONTENTWIDTH  self.contentView.frame.size.width
#define CONTENTHEIGHT  self.contentView.frame.size.height
#import "LSZNetWorkTools.h"
#define VIDEODETAILURL(vid) [NSString stringWithFormat:@"http://box.dwstatic.com/apiVideoesNormalDuowan.php?action=f&vid=%@",vid]

@implementation LOLVideoXTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self=[super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self createView];
        
        
    }
    return self;
    
}

-(void)createView
{
    
    self.videoImageView=[[UIImageView alloc]init];
    [self.contentView addSubview: self.videoImageView];

    
    self.videoTitleLabel=[[UILabel alloc]init];
    [self.contentView addSubview: self.videoTitleLabel];

    self.videoTitleLabel.font=[UIFont boldSystemFontOfSize:17];
    self.videoTitleLabel.numberOfLines=0;
    [self.videoTitleLabel sizeToFit];
    
    self.videoTime=[[UILabel alloc]init];
    self.videoTime.textColor=[UIColor grayColor];
    self.videoTime.font=[UIFont systemFontOfSize:12];
    [self.contentView addSubview: self.videoTime];

    
    self.videoDate=[[UILabel alloc]init];
    self.videoDate.font=[UIFont systemFontOfSize:12];
    self.videoDate.textColor=[UIColor grayColor];
    [self.contentView addSubview: self.videoDate];

    
    self.downloadButton=[LOLBasebutton baseButtonFrame:CGRectZero buttonType:UIButtonTypeCustom buttonTitle:nil buttonTitleColor:nil buttonTag:0 buttonImage:[UIImage imageNamed:@"download"]];
    [self.downloadButton setImage:[UIImage imageNamed:@"stop"] forState:UIControlStateSelected];
    
    [self.downloadButton addTarget:self action:@selector(startDownloadButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.downloadButton];
    
    
    
    
    self.numsLookLabel=[[UILabel alloc]init];
    self.numsLookLabel.font=[UIFont systemFontOfSize:10];
    self.numsLookLabel.textColor=[UIColor whiteColor];
    self.numsLookLabel.textAlignment=NSTextAlignmentRight;
    [self.videoImageView addSubview: self.numsLookLabel];

    
    self.top3Label=[[UILabel alloc]init];
    self.top3Label.font=[UIFont systemFontOfSize:15];
    self.top3Label.textColor=[UIColor whiteColor];
    self.top3Label.textAlignment=NSTextAlignmentCenter;
    [self.videoImageView addSubview: self.top3Label];

    
    
    
    
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    self.videoImageView.frame=CGRectMake(5, 8, (CONTENTWIDTH-20)/3, CONTENTHEIGHT-16);
    self.videoTitleLabel.frame=CGRectMake(5+5+(CONTENTWIDTH-20)/3, 10, CONTENTWIDTH-(5+5+(CONTENTWIDTH-20)/3)-8, 50);
    self.videoTime.frame=CGRectMake(5+5+(CONTENTWIDTH-20)/3, CONTENTHEIGHT-30, 65, 20);
    self.videoDate.frame=CGRectMake(CONTENTWIDTH-35-25-30, CONTENTHEIGHT-30, 50, 20);
    self.downloadButton.frame=CGRectMake(CONTENTWIDTH-35, CONTENTHEIGHT-35, 25, 25);
    
    self.numsLookLabel.frame=CGRectMake(self.videoImageView.frame.size.width-50, self.videoImageView.frame.size.height-20, 50, 20);
    self.top3Label.frame=CGRectMake(0, 0, 20, 20);
    
    
    
}

-(void)startDownloadButton:(UIButton *)button
{
    if (self.downloadVid.length == 6) {
        
        [LSZNetWorkTools getWithUrl:VIDEODETAILURL(self.downloadVid) parameter:nil httpHeader:nil resposeType:ResponseTypeJSON success:^(id result) {
            
            
//            NSString *strUrl =result[@"result"][@"items"][@"350"][@"transcode"][@"urls"][0] ;
            NSString *titleName =@"";
            
            if(![self.videoTitle isEqualToString:@""])
            {
                
                titleName = [self.videoTitle stringByAppendingString:@".mp4"];
            }
            else
            {
                titleName = [[NSString stringWithFormat:@" %@",self.downloadVid]stringByAppendingString:@".mp4"];
            }
            
            
            
//            [[FilesDownManage sharedFilesDownManage] downFileUrl:strUrl filename:titleName filetarget:@"mp4" fileimage:self.image];

            
        } fail:^(NSError *error) {
            
            
        }];

        
        
    }
    
    
}



@end
